# import module
import os
from pdf2image import convert_from_path

def find_pdf_files(directory):
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.lower().endswith('.pdf'):
                filename = (os.path.join(root, file))
                images = convert_from_path(filename)

                for i in range(len(images)):
                    images[i].save(save_folder + '/' + file + "_" + str(i) +'.jpg', 'JPEG')

# 替换为你想要遍历的文件夹路径
folder_path = "/Users/zhoudingduo/Downloads/票据压缩包"
save_folder = "/Users/zhoudingduo/Downloads/output_all"

if not os.path.exists(save_folder):
    os.makedirs(save_folder)

find_pdf_files(folder_path)
